/*
 * Copyright 2011 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.locationbasedagent.server;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.servlet.ServletContext;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class LocationBasedAgentUser {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	  
	@Persistent
	private String firstName;
	  
	@Persistent
	private String lastName;
	  
	@Persistent
	private String phoneNumber;
	  
	@Persistent
	private boolean isAgentUser;
	
	//List of house object keys
	//isAgentUser = true, this is listings the agent owns
	//isAgentUser = false, this is listings the user has as favorites
	@Persistent
	private List<Key> listings;
	  
	public LocationBasedAgentUser(String firstName, String lastName, String phoneNumber, boolean isAgentUser)
	{
		this.firstName = firstName;
		this.lastName = lastName;
		this.phoneNumber = phoneNumber;
		this.isAgentUser = isAgentUser;
		this.listings = new ArrayList<Key>();
	}

	public Key getKey() {
		return key;
	}
	
	public void setKey(Key key) {
		this.key = key;
	}
	
	public String getFirstName() {
		return firstName;
	}
	
	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}
	
	public String getLastName() {
		return lastName;
	}
	
	public void setLastName(String lastName) {
		this.lastName = lastName;
	}
	
	public String getPhoneNumber() {
		return phoneNumber;
	}
	
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	
	public boolean isAgentUser() {
		return isAgentUser;
	}
	
	public void setAgentUser(boolean isAgentUser) {
		this.isAgentUser = isAgentUser;
	}

	private List<Key> getListings() {
		return listings;
	}
	
	//used for isAgentUser = true
	public void addAgentListing(Key newListingID) {
		this.getListings().add(newListingID);
	}
	
	public boolean isThisAgentsListing(Key listingID) {
		return this.getListings().contains(listingID);
	}
	
	//used for isAgentUser = false
	public void addUserFavorite(Key newFavoriteID) {
		this.getListings().add(newFavoriteID);
	}
	
	public boolean isThisUsersFavoriteListing(Key listingID) {
		return this.getListings().contains(listingID);
	}
	
	
	
  
  
  
  
}
